-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #264 #268
Fixes #264 #268
Conversation
With a watchout, a json duplication may not be the best way to do this with typescript as it assumes this object is a data model.
@@ -59,6 +63,13 @@ function kickBot() { | |||
props.battle.removeBot(props.bot); | |||
} | |||
|
|||
// Duplicates this bot and its settings and gives it a new player id. | |||
function duplicateBot() { | |||
let duplicatedBot = JSON.parse(JSON.stringify(props.bot)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
structuredClone
should be cleaner in what you are trying to do here vs pasing object via JSON serialization. It also should be better for typing.
Also change let
to const
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Adjustments made in a877be / 959a9fc, alongside a fix for options not being set by some sort of Id.
…e rather than playerId (resulting in the abiltiy to not uniquely set options for susequent bots).
// Returns a bot by it's PlayerId. Returns undefined if not found.. | ||
public getBotParticipantByPlayerId(playerId: number): User | Bot | undefined { | ||
return this.participants.value.find((participant) => { | ||
const isBot = !("userId" in participant); | ||
if (isBot) { | ||
if (participant.playerId === playerId) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should .find
on this.bots
instead of this.participants
, then you can remove User
from the return type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion!
Addressed in 7bcc76.
@@ -90,6 +90,16 @@ export abstract class AbstractBattle<T extends BattleOptions = BattleOptions> { | |||
}); | |||
} | |||
|
|||
// Returns a bot by it's PlayerId. Returns undefined if not found.. | |||
public getBotByPlayerId(playerId: number): Bot | undefined { | |||
return this.bots.find((bot) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could have been just (bot) => bot.playerId === playerId
but whatever.
Implemented as a dropdown option on a bot participant as shown below, requires validation by @drivver44 as if he feels this is enough for now (perhaps last added AI right click could be an additional issue built from this?).
Two watchouts:
Please feel free to let me know if any of this is incorrect or if I can do anything better, this is my first contribution for this project and felt I could add a very little bit of value with a simple issue.